package com.toutoushidao.ssm.dto;

/**
 * @author laodun
 *
 * error code说明
 * 1xxx:DB异常
 * 2xxx:系统异常
 *
 * 3xxx:应用错误代码
 */
public enum ResultEnum {

    OK(0000, "OK"),

	// 数据库操作异常
	EXCEPTION_DB_INSERT     (1000, "插入失败"),
    EXCEPTION_DB_UPDATE     (1100, "更新失败"),
    EXCEPTION_DB_DELETE     (1200, "删除失败"),
    EXCEPTION_DB_QUERY     (1300, "查询失败"),

    //无法处理的系统异常
    EXCEPTION_SYSTEM        (2000, "系统错误"),
	//验证相关异常
	TOKEN_IS_ILLICIT        (3000, "Token验证非法"),

	// 用户相关异常
	USER_INVALID            (4000, "无效用户"),
    USER_REG_PHONE_REPEAT   (4100, "电话已经被注册"),
    USER_LOGIN_WRONG_PWD   (4200, "用户名或密码错误"),
    USER_WRONG_PWD   (4300, "密码错误"),

	//业务异常
    STORE_BUY_FAIL(5000, "购买失败,已经购买过该设备"),
    STORE_BUY_COIN_LACK(5001, "金币不足"),
	STORE_BUY_STORE_LACK(5002, "库存不足"),
	STORE_EQUIPMENT_NOTEXIST(5003, "装备不存在"),
	STORE_EQUIPMENT_NOT_BELONGS(5004, "用户未购买此设备"),
	STORE_EQUIPMENT_NOT_REGISTED(5005, "该设备未在合作方服务器注册"),
	STORE_ORDER_STATUS_ERROR(5006, "外部订单号为空"),


    FRIEND_REQUEST_NOT_EXIST(5100, "不存在该请求"),
    FRIEND_CANT_REQUEST_SELF(5200, "不能添加自己为好友"),


	//第三方异常
	VIVO_PAY_SIGNATURE_ERROR(6100, "签名验证失败"),
	VIVO_PAY_PUSH_ORDER_ERROR(6110, "调用VIVO支付接口失败"),
	VIVO_PAY_NO_RESPONSE(6120, "调用VIVO支付服务器无响应"),

	//共通
	COMMON_INVALID_PARAM (9000, "参数错误");

	private int code;
	private String msg;

    ResultEnum(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}
	public String getMsg() {
		return msg;
	}

	public String getHtml() {
		StringBuffer sb = new StringBuffer();
		int i = 0;
		for (ResultEnum e : ResultEnum.values()) {

			sb.append("<tr>");
				sb.append("<td>");
					sb.append(++i);
				sb.append("</td>");
				sb.append("<td>");
					sb.append(e.code);
				sb.append("</td>");
				sb.append("<td>");
					sb.append(e.msg);
				sb.append("</td>");
			sb.append("</tr>");

		}
		System.out.println(sb);
		return sb.toString();
	}
}
